package Half_Search;

public class demo1 {
    public static void main(String[] args) {
        int []num = {7,27,37,47,57,67,77,87,97,107,117};
        int n= 127;
        int i = halfSearch(num, n);
        System.out.println(i);
    }
    public static int halfSearch(int []num,int n){
        int min = 0,mid,max = num.length - 1;
        while (true){
            if(min > max){
                return -1;
            }
            mid = (min + max) / 2;
            if(num[mid] < n){
                min = mid + 1;
            } else if (num[mid] > n) {
                max = mid - 1;
            }else {
                return mid;
            }
        }
    }
}
